package com.gym.Thread;

public class WaitTest {

	public static void main(String[] args) {
		Communication communication = new Communication();
		Thread thread = new Thread(communication, "线程一");
		Thread thread1 = new Thread(communication, "线程二");
		thread.start();
		thread1.start();
	}

}
class Communication implements Runnable {
	int i = 1;

	public void run() {
		while (true) {
			synchronized (this) {
				notify();
				if (i <= 100) {
					System.out.println(Thread.currentThread().getName() + ":" + i++);
				} else{
					break;
				}
				try {
					this.wait();
				} catch (InterruptedException e) {
				}
			}
		}
	}
}
